#!/c/chenchang/app/python-3.5.1-embed-amd64/python

from check_file import Check_UTF8, Check_UTF8_BOM, Check_File_Size, sizeof_fmt

import subprocess, sys, os

TOP_LEVEL = None

def Added_And_Changed_Files():
	text = subprocess.check_output(
		["git", "diff", "--cached", "--name-status"],
		stderr=subprocess.STDOUT).decode("utf-8")
	file_list = [(rec[0], rec[2:]) for rec in text.splitlines()]
	return file_list

OK = True

for status, filename in Added_And_Changed_Files():
	if status in ('A', 'M'):
		if not Check_File_Size(filename):
			print("'" + filename + "' is too huge to be commited!")
			OK = False
		if not Check_UTF8(filename) or Check_UTF8_BOM(filename):
			print(filename + " is not UTF-8 (No BOM) encoded.")
			OK = False

exit(0) if OK else exit(-1)
